<?php 
require 'dbconnect.php';
session_start();
$cid = $_POST['courseid'];
$sid = $_SESSION['id'];
$result = mysql_query("SELECT CourseScheduleID From CourseSchedule where CourseID = '$cid'");
$csid = mysql_fetch_array($result);
mysql_query("INSERT INTO StudentCourse(StudentID, CourseScheduleID) VALUES ($sid,$csid[0])");
header("location: mycourses.php");
?>